package com.RedRiver.hospitalsystem.finance_service.service.impl;

import com.RedRiver.hospitalsystem.finance_service.common.WoniuxyBeanCopyUtil;
import com.RedRiver.hospitalsystem.finance_service.common.exception.PaymethodException;
import com.RedRiver.hospitalsystem.finance_service.infra.mapper.PaymentMapper;
import com.RedRiver.hospitalsystem.finance_service.infra.model.Payment;
import com.RedRiver.hospitalsystem.finance_service.infra.model.Paymethod;
import com.RedRiver.hospitalsystem.finance_service.service.PaymentService;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymentInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymentInfoList;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymethodInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.PaymethodInfoList;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {

    @Resource
    private PaymentMapper paymentMapper;
    @Override
    public PaymentInfoList findAll() {
        PaymentInfoList paymentInfoList = new PaymentInfoList();
        ArrayList<PaymentInfo> paymentInfos = new ArrayList<>();
        List<Payment> payments = paymentMapper.selectList(null);
        if (null==payments||payments.size()==0)throw new PaymethodException(50001,"没有缴费类别");
        for (Payment payment  : payments) {
            PaymentInfo copyone = WoniuxyBeanCopyUtil.copyone(payment, PaymentInfo.class);
            paymentInfos.add(copyone);
        }
        paymentInfoList.setList(paymentInfos);
        return paymentInfoList;
    }
}
